package com.wei.miaosha.dao;


import com.wei.miaosha.domain.*;
import org.apache.ibatis.annotations.*;

/**
 * Created by Weizichen on 2018/8/19.
 * desc:订单接口
 */
@Mapper
public interface OrderDao {
    @Select("select * from miaosha_order where user_id =#{userId} AND goods_id=#{goodsId}")
    MiaoshaOrder getMiaoshaOrderByGoodsId(@Param("userId") long userId, @Param("goodsId") long goodsId);

    @Insert("insert into order_info(user_id, goods_id, goods_name, goods_count, goods_price, order_channel, status, create_date)values(" +
            "#{userId}, #{goodsId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel},#{status},#{createDate} )")
    @SelectKey(keyColumn = "id", keyProperty = "id", resultType = long.class, before = false, statement = "select last_insert_id()")
    long insert(OrderInfo orderInfo);

    @Insert("insert into miaosha_order (user_id, goods_id, order_id)values(#{userId}, #{goodsId}, #{orderId})")
    long insertMiaoshaOrder(MiaoshaOrder miaoshaOrder);

    @Select("SELECT * FROM order_info WHERE id=#{orderId}")
    OrderInfo getOrderById(@Param("orderId") long orderId);

}
